 package CurtainDesign.utils;

 import CurtainDesign.MainView;
 import CurtainDesign.OrderInfo;
 import java.awt.BorderLayout;
 import java.awt.Color;
 import java.awt.Dimension;
 import java.awt.FlowLayout;
 import java.awt.Font;
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
 import java.awt.Toolkit;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
 import java.awt.event.KeyEvent;
 import java.awt.event.KeyListener;
 import java.awt.event.WindowEvent;
 import java.awt.event.WindowListener;
 import javax.swing.JButton;
 import javax.swing.JDialog;
 import javax.swing.JLabel;
 import javax.swing.JOptionPane;
 import javax.swing.JPanel;
 import javax.swing.JTextField;

 public class TPoleInputDialog extends JDialog
 {
   private static final long serialVersionUID = 1L;
   private int tPoleNum = 0;

   private MainView parentWin = null;

   private JTextField outTxt = null;

   private int level = 0;

   public TPoleInputDialog(MainView parent, JTextField theOutTxt, int poleNum, int theLevel)
   {
     super(parent, true);
     this.parentWin = parent;
     this.outTxt = theOutTxt;
     this.tPoleNum = poleNum;
     this.level = theLevel;
     initUI();
   }

   public int getTPoleNum()
   {
     return this.tPoleNum;
   }

   public void setTPoleNum(int poleNum) {
     this.tPoleNum = poleNum;
   }

   public void show()
   {
     addWindowListener(new WindowListener()
     {
       public void windowActivated(WindowEvent e) {
       }

       public void windowClosed(WindowEvent e) {
       }

       public void windowClosing(WindowEvent e) {
         TPoleInputDialog.this.closeDlg();
         TPoleInputDialog.this.parentWin.show();
       }

       public void windowDeactivated(WindowEvent e)
       {
       }

       public void windowDeiconified(WindowEvent e)
       {
       }

       public void windowIconified(WindowEvent e)
       {
       }

       public void windowOpened(WindowEvent e)
       {
       }
     });
     super.show();
   }

   private void closeDlg()
   {
     dispose();
   }

   private void initUI()
   {
     JPanel contentpane = (JPanel)getContentPane();
     contentpane.setLayout(new BorderLayout());
     JPanel uppane = new JPanel();
     JPanel botpane = new JPanel();
     contentpane.add(uppane, "Center");
     contentpane.add(botpane, "South");

     GridBagLayout gbl = new GridBagLayout();
     GridBagConstraints gbc = new GridBagConstraints();
     gbc.fill = 2;
     gbc.anchor = 13;
     gbc.insets = new Insets(15, 15, 15, 15);
     uppane.setLayout(gbl);

     JLabel[] labels = new JLabel[this.tPoleNum];
     JTextField[] pos = new JTextField[this.tPoleNum];
     JButton okbt = new JButton("确定");
     JButton cancelbt = new JButton("取消");

     JLabel promotion = new JLabel("请从左到右依次输入T型立杆的位置(mm):");
     promotion.setFont(new Font("Dialog", 0, 13));
     promotion.setForeground(Color.BLUE);
     gbc.gridwidth = 0;
     gbc.ipadx = 5;
     gbc.ipady = 5;
     gbl.setConstraints(promotion, gbc);
     uppane.add(promotion);

     for (int i = 0; i < this.tPoleNum; i++)
     {
       labels[i] = new JLabel("T型立杆位置" + (i + 1));
       labels[i].setFont(new Font("Dialog", 0, 13));
       gbc.gridwidth = 1;
       gbc.ipadx = 5;
       gbc.ipady = 0;

       gbl.setConstraints(labels[i], gbc);
       uppane.add(labels[i]);

       pos[i] = new JTextField();
       pos[i].setFont(new Font("Dialog", 0, 13));
       gbc.gridwidth = 0;
       gbc.ipadx = 150;
       gbc.ipady = 0;
       gbl.setConstraints(pos[i], gbc);
       uppane.add(pos[i]);
       pos[i].addKeyListener(new KeyListener()
       {
         public void keyTyped(KeyEvent e) {
         }

         public void keyReleased(KeyEvent e) {
           JTextField txt = (JTextField)(JTextField)e.getSource();
           String str = txt.getText();
           if (!CurtainChecker.isNumber(str))
           {
             TPoleInputDialog.this.getToolkit().beep();
             e.consume();
             JOptionPane.showMessageDialog(null, "请仅输入数字", "错误", 0);
             str = str.substring(0, str.length() - 1);
             txt.setText(str);
           }
         }

         public void keyPressed(KeyEvent e)
         {
         }
       });
     }
     botpane.setLayout(new FlowLayout());
     okbt.setFont(new Font("Dialog", 0, 13));
     cancelbt.setFont(new Font("Dialog", 0, 13));
     botpane.add(okbt);
     botpane.add(cancelbt);

     Dimension outframesize = ((MainView)getOwner()).getSize();
     Dimension size = new Dimension();
     size = getPreferredSize();
     setSize(size);
     int x0 = ((MainView)getOwner()).getX();
     int y0 = ((MainView)getOwner()).getY();
     // setLocation(x0 + (outframesize.width - size.width)  2);
     setLocation(null); // todo

//     okbt.addActionListener(new ActionListener(pos) { private final JTextField[] val$pos;
//
//       public void actionPerformed(ActionEvent action) { String posstr = "";
//         for (int i = 0; i < TPoleInputDialog.this.tPoleNum; i++) {
//           if (this.val$pos[i].getText().toString().equals(""))
//           {
//             JOptionPane.showMessageDialog(null, "T型立杆位置不能为空！", "错误", 0);
//             return;
//           }
//           if (i < TPoleInputDialog.this.tPoleNum - 1)
//           {
//             posstr = posstr + this.val$pos[i].getText() + ",";
//           }
//           else
//           {
//             posstr = posstr + this.val$pos[i].getText();
//           }
//         }
//         if (TPoleInputDialog.this.level == 1)
//         {
//           TPoleInputDialog.this.parentWin.GetOrderInfo().SaveTPolePos(posstr);
//         }
//         else if (TPoleInputDialog.this.level == 2)
//         {
//           TPoleInputDialog.this.parentWin.GetOrderInfo().saveBottomTPolePos(posstr);
//         }
//         TPoleInputDialog.this.outTxt.setText(posstr);
//         TPoleInputDialog.this.outTxt.setEnabled(true);
//         TPoleInputDialog.this.outTxt.setEditable(false);
//         TPoleInputDialog.this.closeDlg();
//         TPoleInputDialog.this.parentWin.show();
//       }
//     });
     cancelbt.addActionListener(new ActionListener() {
       public void actionPerformed(ActionEvent ae) {
         TPoleInputDialog.this.closeDlg();
         TPoleInputDialog.this.parentWin.show();
       }
     });
   }
 }

/* Location:           C:\Users\Administrator\Desktop\奥特百叶窗\Shutter DesignerV3.1\CurtainDesign.jar
 * Qualified Name:     CurtainDesign.utils.TPoleInputDialog
 * JD-Core Version:    0.6.0
 */